import { usePermission } from "@/hooks/web/usePermission";

const isAuth = (el, binding) => {
  const { hasPermission } = usePermission();
  const value = binding.value;
  if(!value) return;
  if(!hasPermission(value)){
    const node = el.parentNode;
    if(node) node.removeChild(el);
  }
  
}

const authDirective = {
  mounted(el, binding) {
    isAuth(el, binding);
  }
}

export function setupPermissionDirective(app) {
  app.directive('auth', authDirective);
}

export default authDirective